<template>
  <div class="login-page">
    <van-nav-bar title="注册账号" @click-left="$router.back()">
      <template #left>
        <van-icon name="arrow-left" color="white" @click="$router.back()" />
      </template>
    </van-nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入用户名或者账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 25px">
        <van-button round block type="info" native-type="submit">登&nbsp;录</van-button>
      </div>
    </van-form>
    <div class="link"><router-link to="/login">去登录~</router-link></div>
  </div>
</template>

<script>
import { register } from '@/api/user'
export default {
  name: 'register-page',
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit(values) {
      // console.log('submit', values)
      await register(values)
      // 成功后 跳转登录页
      this.$toast.success('注册成功!')
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 14px;
  text-align: center;
  margin-top: 35px;
}
.van-field {
  margin-top: 25px;
  ::placeholder {
    font-size: 17px;
  }
}
.van-button--normal {
  font-size: 17px;
  margin-top: 30px;
  height: 50px;
  background-color: #069;
}
::v-deep .van-nav-bar__content {
  background-color: #069;
}
</style>
